﻿//--------------------------------------------------------------------------------------------------------------------------------
// <copyright file="RectangularElementLocation2D.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>Exul</author>
//--------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.FiniteElementMethod
{
    using System;

    /// <summary>Represents location of a rectangular element in the two-dimensional space.</summary>
    public sealed class RectangularElementLocation2D
    {
        /// <summary>The minimal acceptable size of element.</summary>
        /// <remarks>
        ///     This value represents minimal acceptable difference
        ///     between <see cref="Left"/> and <see cref="Right"/> and
        ///     between <see cref="Bottom"/> and <see cref="Top"/>.
        /// </remarks>
        public const double MinimalSize = 1e-16;

        /// <summary>Initializes a new instance of the <see cref="RectangularElementLocation2D"/> class.</summary>
        /// <param name="leftBorder">The left border.</param>
        /// <param name="rightBorder">The right border.</param>
        /// <param name="bottomBorder">The bottom border.</param>
        /// <param name="topBorder">The top border.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     <paramref name="rightBorder"/> is less than <paramref name="leftBorder"/> or
        ///     greater than it less than <see cref="MinimalSize"/>.
        ///     <para>--or--</para>
        ///     <para>
        ///         <paramref name="rightBorder"/> is less than <paramref name="leftBorder"/> or
        ///         greater than it less than <see cref="MinimalSize"/>.
        ///     </para>
        /// </exception>
        public RectangularElementLocation2D(double leftBorder, double rightBorder, double bottomBorder, double topBorder)
        {
            #if SAFE

            if (rightBorder - leftBorder < 1e-16)
            {
                throw ThrowHelper.InvalidLocation("leftBorder", leftBorder, "rightBorder", rightBorder, MinimalSize);
            }

            if (topBorder - bottomBorder < 1e-16)
            {
                throw ThrowHelper.InvalidLocation("bottomBorder", bottomBorder, "topBorder", topBorder, MinimalSize);
            }

            #endif

            this.Left = leftBorder;
            this.Right = rightBorder;
            this.Bottom = bottomBorder;
            this.Top = topBorder;
        }

        /// <summary>Gets the left border.</summary>
        /// <value>The left border.</value>
        public double Left
        {
            get;
            private set;
        }

        /// <summary>Gets the right border.</summary>
        /// <value>The right border.</value>
        public double Right
        {
            get;
            private set;
        }

        /// <summary>Gets the bottom border.</summary>
        /// <value>The bottom border.</value>
        public double Bottom
        {
            get;
            private set;
        }

        /// <summary>Gets the top border.</summary>
        /// <value>The top border.</value>
        public double Top
        {
            get;
            private set;
        }

        /// <summary>Gets the location of an element by the first axis.</summary>
        /// <value>The location of an element by the first axis.</value>
        public Location1D LocationByFirstAxis
        {
            get
            {
                return new Location1D(this.Left, this.Right);
            }
        }

        /// <summary>Gets the location of an element by the second axis.</summary>
        /// <value>The location of an element by the second axis.</value>
        public Location1D LocationBySecondAxis
        {
            get
            {
                return new Location1D(this.Bottom, this.Top);
            }
        }
    }
}